﻿#include <QCoreApplication>
#include <QString>
#include <QDebug>
#pragma execution_character_set("utf-8")                      //涉及中文字符输入说明


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QList<QString> strs = QList<QString>()<<"你 _a&" << "你 _ab" << "你 _a%";//硬编码输入
    QString getLongestCommonPrefix(QList<QString> strs);
    QString LongestCommonPrefix=getLongestCommonPrefix(strs);           //调用函数
    qDebug()<<LongestCommonPrefix;//console输出
    return a.exec();
}

QString getLongestCommonPrefix(QList<QString> strs)
{
    int num = 0;                                //重复字符数量
    for (int j = 1; j <strs[0].size(); ++j){
        for (int i = 1; i < strs.length(); ++i)
        {
            if(strs[0].left(j)!=strs[i].left(j)){
                goto outloop;
            }
        }
        num++;
    }
    outloop:
    QString LongestCommonPrefix = strs[0].left(num);
    return LongestCommonPrefix;
}
